package cj.web.marry.dao;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;

@DAO
public interface MarryTJDAO {

	@ReturnGeneratedKeys
	@SQL("INSERT INTO MarriageTJ (code,man,manPhone,woman,womanPhone,createAt,status,addressId,interesting,openid) VALUES (:1,:2,:3,:4,:5,now(),:6,:7,:8,:9) ")
	int create(String code, String man, String manPhone, String woman,String womanPhone, int status,String addressId,String interesting,String openId);

	@SQL("SELECT count(1) FROM MarriageTJ WHERE code =:1 AND man =:2  AND manPhone=:3 AND woman=:4 AND womanPhone=:5 AND interesting=:6 ")
	int marryTjCount(String code, String man, String manPhone, String woman,String womanPhone,String interesting);
	
	@SQL("SELECT * FROM MarriageTJ WHERE id =:1 ")
	List<Map> getMarriageTJList(int id);
	
	@SQL("SELECT * FROM MarriageTJ WHERE openid =:1 ")
	List<Map> getMarriageTJListByOpenid(String openId);
	
	@SQL("UPDATE MarriageTJ SET hash=:2 WHERE id=:1 ")
    void update(int id,String hash);
	
	@SQL("UPDATE MarriageTJ SET code=:1,man=:2,manPhone=:3,woman=:4,womanPhone=:5,addressId=:6,interesting=:7 WHERE openid=:8 ")
    void update(String code, String man, String manPhone, String woman,String womanPhone,String addressId,String interesting,String openId);

	@SQL("SELECT * FROM MarriageTJ WHERE addressId=:1  #if(:2!=''){ and (manPhone like '%##(:2)%' or womanPhone like '%##(:2)%')} ")
	List<Map> getMarriageTJListByPhone(int addressId,String phone);
}
